<?php
/*
 * @Author: 李明
 * @Date: 2021-12-29 18:48:41
 * @LastEditTime: 2021-12-29 19:11:19
 * @LastEditors: 李明
 * @Description: 
 * @FilePath: /CRM2.0-PHP/app/Http/Controllers/invoice/InvoiceController.php
 * @山东壹零贰肆信息科技有限公司
 */

namespace App\Http\Controllers\invoice;

use App\Http\Controllers\common\LMReturn;
use App\Http\Controllers\Controller;
use App\Models\Invoice;
use Illuminate\Http\Request;

class InvoiceController extends Controller
{
    public function changeInvoice(Request $request)
    {
        try {
            //去验证token值
            $tokenInfo = json_decode($this->verifyTokenLm(), true);
            //判断传递过来的token的code码是否等于400  如果是400的话，提示token不正确
            if ($tokenInfo['code'] == 400) {
                return LMReturn::Error($tokenInfo['msg'], $tokenInfo['code']);
            }
            //接收前端传递过来的值
            $all = $request->all();
            $name = $all['name'];
            $id_number = $all['id_number'];
            $open_bank = $all['open_bank'];
            $bank_number = $all['bank_number'];
            $address = $all['address'];
            $tel = $all['tel'];
        } catch (\Throwable $th) {
            return LMReturn::Error('参数处理发生错误', 'ICCI1');
        }
        try {
            $invoice = Invoice::find(1);
            $invoice->name = $name;
            $invoice->id_number = $id_number;
            $invoice->open_bank = $open_bank;
            $invoice->bank_number = $bank_number;
            $invoice->address = $address;
            $invoice->tel = $tel;
            $invoice->save();
            return LMReturn::Success($invoice, '修改成功');
        } catch (\Throwable $th) {
            return LMReturn::Error('处理参数发生错误', 'ICCI2');
        }
    }
    public function queryInvoice(Request $request)
    {
        try {
            //去验证token值
            $tokenInfo = json_decode($this->verifyTokenLm(), true);
            //判断传递过来的token的code码是否等于400  如果是400的话，提示token不正确
            if ($tokenInfo['code'] == 400) {
                return LMReturn::Error($tokenInfo['msg'], $tokenInfo['code']);
            }
            return LMReturn::Success(Invoice::find(1));
        } catch (\Throwable $th) {
            return LMReturn::Error('参数处理发生错误', 'ICCI1');
        }
    }
}
